use futures::executor::block_on;
use tuleap::tuleap_client::TuleapClient;

#[tokio::test]
pub(crate) async fn test_artifact_detail() {
     // RUST_LOG=trace cargo run
     if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "tuleap=trace");
    }

    tracing_subscriber::fmt::init();

    let tuleap_client = TuleapClient::new(
        String::from("https://192.168.1.20/"),
        String::from("tlp-k1-5.605bf7a8dae7c732ff3207981e5f9ee60a275e8bc1f855a43471b204ff1e7ea3"),
    );

    let response = tuleap_client.tracker_detail(&68).await;

    println!("response:{:?}", response);
}

#[tokio::test]
pub(crate) async fn test_search_artifact_from_tracker_eq_title() {
     // RUST_LOG=trace cargo run
     if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "tuleap=trace");
    }

    tracing_subscriber::fmt::init();

    let tuleap_client = TuleapClient::new(
        String::from("https://192.168.1.20/"),
        String::from("tlp-k1-5.605bf7a8dae7c732ff3207981e5f9ee60a275e8bc1f855a43471b204ff1e7ea3"),
    );

    let response = tuleap_client.search_artifact_from_tracker_eq_title(&68, &String::from("[2023春季版]->我的任务-考试详情-考试结果-试题解析（列表）")).await;

    println!("response:{:?}", response);
}

#[tokio::test]
pub(crate) async fn test_import() {
    std::env::set_var("RUST_LOG", "tuleap=info");
    tracing_subscriber::fmt::init();

    let tuleap_client = TuleapClient::new(
        String::from("https://192.168.1.20/"),
        String::from("tlp-k1-5.605bf7a8dae7c732ff3207981e5f9ee60a275e8bc1f855a43471b204ff1e7ea3"),
    );

    tuleap_client.import(&68, &String::from("/Users/tom/Downloads/技术部-SAAS2.0开发跟进表.xlsx"), &String::from("Sheet1")).await;
}


#[tokio::test]
pub async fn test_search_artifact_from_tracker_contains_title(){
    std::env::set_var("RUST_LOG", "tuleap=trace");
    tracing_subscriber::fmt::init();

    let tuleap_client = TuleapClient::new(
        String::from("https://192.168.1.20/"),
        String::from("tlp-k1-5.605bf7a8dae7c732ff3207981e5f9ee60a275e8bc1f855a43471b204ff1e7ea3"),
    );
    let res = tuleap_client.search_artifact_from_tracker_contains_title(&68, &String::from("[2023春季版]->")).await.unwrap();

    for a in res.as_array().unwrap() {
        println!("res:{:?}", a.as_object().unwrap().get("id").unwrap().as_u64().unwrap());    
        let id = a.as_object().unwrap().get("id").unwrap().as_u64().unwrap();
        
        // tuleap_client.delete_artifact_by_id(&id).await;
    }

}